package com.wang.springsession.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author: wang
 * @date: 2021/7/27 19:09
 * @description:
 */
@Controller
public class SessionTest {

    @RequestMapping("s1/get")
    @ResponseBody
    public String get(HttpSession session){
        Object user = session.getAttribute("user");
        if ( user == null ){
            return "nothing";
        }
        return "yes you get it"+user;
    }

    @RequestMapping("s1/set")
    @ResponseBody
    public String set(HttpSession session){
        String user = "user";
        session.setAttribute("user",user);
        return "user has been set in session";
    }
}
